package com.itheima.recursion_single;

/**
 * 递归反向打印字符串
 *
 * @FileName ReversePrintString
 * @Description
 * @Author Sword
 * @date 2025-03-11
 **/
public class ReversePrintString {

    public static void f1(int index, String str) {
        if (index == str.length()) {
            return;
        }
        f1(index + 1, str);
        System.out.println(str.charAt(index));
    }

    public static void f2(int index, String str) {
        if (index == -1) {
            return;
        }
        System.out.println(str.charAt(index));
        f2(index - 1, str);
    }


    public static void main(String[] args) {
        f1(0, "1234");
        System.out.println();
        f2(3,"1234");
    }
}
